package com.tl.khadmin.service.impl;

import java.util.HashMap;
import java.util.Map;

import javax.annotation.Resource;
import javax.servlet.http.HttpSession;

import org.springframework.stereotype.Service;

import com.tl.khadmin.bean.Supplier;
import com.tl.khadmin.enums.OrderStateEnum;
import com.tl.khadmin.mapper.StatisticsMapper;
import com.tl.khadmin.service.StatisticsIService;
import com.tl.khadmin.util.Constant;
import com.tl.khadmin.util.PutParamUtil;

@Service
public class StatisticsServiceImpl implements StatisticsIService{
	
	@Resource
	private StatisticsMapper statisticsMapper;

	@Override
	public Map<String, Object> index(HttpSession session) {
		
		Map<String, Object> ret = new HashMap<String, Object>();
		
		Map<String, Object> queryOrderParam = new HashMap<String, Object>();
		queryOrderParam.put("dayStartTime", "2021-08-13 05:34:24");	//当天开始时间
		queryOrderParam.put("dayEndTime", "2021-08-13 23:34:24");	//当前结束时间
		queryOrderParam.put("monthStartTime", "2021-08-01 23:34:24");	//当月开始时间
		queryOrderParam.put("monthEndTime", "2021-08-31 23:34:24");	//当月结束时间
		queryOrderParam.put("dayCompleted", OrderStateEnum.已付款.code());	//查询当天该状态的订单
		queryOrderParam.put("monthCompleted", OrderStateEnum.已付款.code());	//查询当月该状态的订单
		Supplier supplier = (Supplier) session.getAttribute(Constant.USER_SUPPLIER);
        PutParamUtil.setParamIsInterior(supplier, queryOrderParam);	//设置查询供应商数据范围
		Map<String, Object> orderCount = statisticsMapper.countOrder(queryOrderParam);
		ret.put("orderCount", orderCount);
		
		PutParamUtil.setParamIsInterior(supplier, queryOrderParam);	//设置查询供应商数据范围
		Map<String, Object> countProduct =  statisticsMapper.countProduct();
		ret.put("countProduct", countProduct);
		
		if(supplier.getIsInterior() == 1){
			Map<String, Object> countSupplier =  statisticsMapper.countSupplier();
			ret.put("countSupplier", countSupplier);
		}
		 
		return ret;
	}
	
	
	
}
